package com.smedi.ismedi.authority.starter.config;

import com.smedi.ismedi.authority.starter.feign.AuthorityAccessFeignClient;
import com.smedi.ismedi.authority.starter.property.AuthorityFeignHeaderForwardProperty;
import com.smedi.ismedi.authority.starter.util.AuthorityUtil;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnClass({
        AuthorityUtil.class
})
@ComponentScan({
        "com.smedi.ismedi.authority.starter.property",
        "com.smedi.ismedi.authority.starter.handler",
        "com.smedi.ismedi.authority.starter.config",
        "com.smedi.ismedi.authority.starter.aspect"
})
@EnableFeignClients(basePackages = {
        "com.smedi.ismedi.authority.starter.feign",
}, basePackageClasses = {
        AuthorityAccessFeignClient.class
})
@Slf4j
public class AuthorityAutoConfig {
    /**
     * 自动装载
     *
     * @param clz
     * @param <T>
     * @return
     * @throws InstantiationException
     * @throws IllegalAccessException
     */
    private <T> T assemble(Class<T> clz) throws InstantiationException, IllegalAccessException {
        log.info("装配：{}", clz.getName());
        return clz.newInstance();
    }

    @Bean
    public AuthorityFeignHeaderForwardProperty authorityFeignHeaderForwardProperty(){
        return new AuthorityFeignHeaderForwardProperty();
    }
}